/**
 * Created by Maibenben on 2017/5/4.
 */
$(function () {
    //跳转到本页之后读取cookie中是否有mid和token
    checkCookie();
    //读取一下本地缓存
    var desc = localStorage.getItem("desc");//病情描述
    var doc_id = localStorage.getItem("doc_id");//医师id
    var member_id = localStorage.getItem("member_id");//就诊人id
    var work_time = localStorage.getItem("work_time");//预约时间
    var curr = new Date();
    var date = curr.getFullYear() + "-" + (curr.getMonth() + 1) + "-" + (parseInt(curr.getDate()) + parseInt(location.search.split("=")[3]));
    $(".appoint_time").text(date + " " + work_time);
    //进入页面显示上一个页面传过来的信息
    $.get(infoCheckURL + "?id=" + member_id + "&d_id=" + doc_id + "&mid=" + $.cookie("mid") + "&token=" + $.cookie("token"), function (data) {
        $(".load").css("display", "none");
        $(".appoint_doctor").text(data.data.doctor.data.name);
        $(".appoint_office").text(data.data.doctor.data.depart_desc);
        $(".appoint_address").text(data.data.doctor.data.origin_company);
        $(".mem-name").text(data.data.member.data.name);
        $(".mem-birthday").text(data.data.member.data.birthday);
        $(".mem-tel").text(data.data.member.data.mobile);
        $("#main").css("display", "block");
    });
    //是否接受约定
    $(".agree").children("input").click(function () {
        if ($(".agree").children("input").prop("checked")) {
            $(".footer").css("background", "rgb(47,178,159)");
        } else {
            $(".footer").css("background", "#ccc");
        }
    });
    //点击下一步跳转到支付订单
    $(".footer").click(function () {
        //是否接受约定
        if ($(".agree").children("input").prop("checked")) {
            //将预约信息保存起来
            var dataPush = {
                m_id: parseInt(member_id),
                token: $.cookie("token"),
                d_id: doc_id,
                mark_time: date + " " + work_time,
                describe: desc,
                pics: localStorage.getItem("base")
            };
            console.log(dataPush);
            $.post(infoAddURL, dataPush, function () {
                console.log("提交订单成功");
                //进入下一个页面
                window.location.href = "purchase.html";
            });
        }
    });
});